package n3278;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	
	static int N,K,max=100000;
	
	static boolean visited[]=new boolean[max+1];
	
	static int[][] list=new int[max+1][2];
	
	static int bfs()
	{
		if(N==K)return 0;
		int i=0,count=1;
		list[0][0]=N;
		list[0][1]=0;
		visited[N]=true;
		while(i<count)
		{
			int cur=list[i][0];
			int step=list[i][1];
			if(cur-1>=0&&cur-1<=max)
			{
				int t=cur-1;
				if(t==K){
					return step+1;
				}
				if(!visited[t])
				{
					list[count][0]=t;
					list[count][1]=step+1;
					count++;
					visited[t]=true;
				}
			}
			
			if(cur+1<=max&&cur+1>=0)
			{
				int t=cur+1;
				if(t==K){
					return step+1;
				}
				if(!visited[t])
				{
					list[count][0]=t;
					list[count][1]=step+1;
					count++;
					visited[t]=true;
				}
			}
			
			if(cur*2<=max&&cur*2>=0)
			{
				int t=cur*2;
				if(t==K){
					return step+1;
				}
				if(!visited[t])
				{
					list[count][0]=t;
					list[count][1]=step+1;
					count++;
					visited[t]=true;
				}
			}
			i++;
		}
		return 0;
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub
		
		BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
		String line=bf.readLine();
		StringTokenizer st=new StringTokenizer(line);
		N=Integer.parseInt(st.nextToken());
		K=Integer.parseInt(st.nextToken());
		System.out.println(bfs());
	}

}
